/*
 * Copyright @ 苏州瑞云信息技术有限公司 All rights reserved.
 */
package cn.com.recloud.bbs.controller;

import cn.com.recloud.bbs.vo.OpenLogVO;
import cn.com.recloud.core.util.Result;
import cn.com.recloud.one.spring.exception.OneException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.*;

import cn.com.recloud.one.spring.controller.BaseController;

import cn.com.recloud.bbs.entity.bbs_opened_log;
import cn.com.recloud.bbs.service.OpenedLogService;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author keblea xie
 * @date 2020-06-08
 */
@RestController
@RequestMapping("/api/bbs/openedlog")
@Api(tags = "个人中心最近浏览相关接口")
public class OpenedLogController extends BaseController<bbs_opened_log,OpenedLogService> {
    @Resource
    OpenedLogService openedLogService;

    @PostMapping("saveopenlog/{type}")
    @ApiOperation("保存文章活动被打开记录")
    public Result saveOpenLog(@PathVariable("type")String type, @RequestBody bbs_opened_log bbsOpenedLog){
        openedLogService.saveOpenLog(bbsOpenedLog,type);
        return Result.SUCCESS;
    }

    @GetMapping("opendlist")
    @ApiOperation("最新浏览文章活动列表")
    public Result opendList(String name,String type,
                            @RequestParam(required = false,defaultValue = "1") Integer pageIndex,
                            @RequestParam(required = false,defaultValue = "15") Integer pageSize){
        if(StringUtils.isBlank(type)){
            throw new OneException("类型不能为空");
        }
        List<OpenLogVO> list = openedLogService.findOpendList(name,type,pageIndex,pageSize);
        return new Result(list);
    }
}

